home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12440 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: File Open Problem - Please provide clues
  5. Date: 30 Mar 1996 22:25 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <30MAR199622252431@erich.triumf.ca>
  9. References: <4jkq8h$1it6@useneta1.news.prodigy.com>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4jkq8h$1it6@useneta1.news.prodigy.com>, DPMU12A@prodigy.com (Steve Bailey) writes...
  14. >Hi I'm having problems with opening files which are named   
  15. >after simple numbers:                                       
  16. >2                                                           
  17. >5, etc.                                                     
  18. >The reason for naming them this way is because I'm writing a
  19. >program in C that increments a number, and then attempts to 
  20. >open the file that's actually named by that number.         
  21. >I get mismatched type errors when using FOPEN:              
  22. > int num;                                                   
  23. > filepointer = FOPEN(num,"r");            or                           
  24. > filepointer = FOPEN("num","r");
  25.  
  26. don't know about FOPEN(), but fopen() requires a string as it's first argument.
  27.  
  28. Try something like:
  29.     char fnstring[20];
  30.     int num;
  31.     ....
  32.     sprintf(fnstring, "%d", num);
  33.     if((fp = fopen(fnstring, "r") == NULL)
  34.         /* error...*/
  35.     
  36. > I was going to name the files:                             
  37. >  0.txt, 1.txt, 2.txt,                                      
  38. > and so forth, but this was even trickier with the string   
  39. >concatenating, (attached ".txt" to it) etc.. so the files   
  40. >are named after numbers simply..                            
  41.  
  42. This shold be quite trivial, now that you've seen what I did above...
  43.  
  44.     sprintf(fnstring,"%d.txt", num);
  45.  
  46.  
  47.  
  48. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  49. Internet: bennett@triumf.ca         | of one another only when one can be
  50. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  51. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  52. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  53. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.